package com.biodiversitydigit.models
{
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.core.Application;
	
	import org.gaeswf.Service;
	

	public class DataModel
	{
	
		//General purpose vars from startup
		public static var amfEndPoint:String = Application.application.parameters.amfEndPoint;		
		
		[Bindable] public static var logedUser:User; //Of Distribution objects
		[Bindable] public static var activeDistributions:ArrayCollection; //Of Distribution objects
		
		
		
		public static function init():void
		{			
			// Listen for service events
			listen("login");
			listen("createNewUser");
			
			logedUser = new User();
			
		}
		
		//--------------------------------------------------
		// Service handlers
		public static function loginResponse(result:Object):void
		{
			logedUser.id = result.id;
			logedUser.name = result.name;
			logedUser.email = result.email;
			logedUser.web = result.web;
		}
		
		// Service handlers
		public static function createNewUserResponse(result:Object):void
		{
			//service returns a Number
		}
		
		// Service handlers
		public static function createNewUserFault(result:Object):void
		{
			Alert.show('errorId : ' + result.errorID + ' ' + result.faultString);
		}

		
		// Private methods
		
		// Service listener helper
		private static function listen(serviceName:String):void
		{
			// Add the model as a listener for service responses.
			Service.listen(serviceName, DataModel);
		} 
		
		
		
	}
}